<template>
  <div class="top-header">
    <div class="header-container">
      <!-- <div class="top-left"> -->
        <!-- <img src="../assets/images/logo_wh.png" alt="logo" class="img" width="30"> -->
        <span class="desc">识别检测管理系统</span>
      <!-- </div> -->
    </div>
  </div>
</template>

<script>
  import md5 from "md5";
  export default {
    
    data() {
      return {
        userName: "",
        curPathIndex: 0,    //选中父级菜单下标
        curPath: '',    //选中的子级菜单
        showDrawer: false,    //是否显示场内飞行计划统计弹框
        menuItemList: [],
        /* 修改密码 */
        isDialogPwd:false,
        name:'',
        oldPwd:'', 
        newPwd:'',
        newPwdBak:'',
        

        /* 编辑用户信息 */
        isDialogVisible: false,//编辑添加用户信息弹框
        formLabelWidth: '150px',
        infoType: 3,//1->新增 2->编辑 3->修改基础信息  用户入口

        /* 我的档案 */
        isDialogBaseInfo: false,
        userId:'',//当前用户id
        address: '',//地址
        loginName: '',//用户名          
        name: '',//真实姓名
        mobile: '',//电话
        sex: 1,//性别
        groupId: '',//权限
        enlistDate: '',//入伍日期
        departmentName: '',//所属部门
        position: '',//职位
        sexName:{'1':'男','2':'女'},




        menuList: [],   //菜单按钮
      }
    },
    created() {
      this.menuList = [
         {
          powerName: "我的",
          // powerUrl: "/experimentTask",
          powerUrl: "/myManage",
          children: []
        },{
          powerName: "试验任务",
          // powerUrl: "/experimentTask",
          children: [{
             powerName: "试验任务",
             powerUrl: "/experimentTask",
          },{
             powerName: "试验科目",
             powerUrl: "/experimentSubject",
          }]
        },{
          powerName: "试验资源",
          // powerUrl: "/experimentsResources",
          children: [{
             powerName: "类别",
             powerUrl: "/experimentsResources",
          },{
             powerName: "人员",
             powerUrl: "/experimentsPersonnel",
          },{
             powerName: "装备",
             powerUrl: "/experimentsEquipment",
          },{
             powerName: "场地",
             powerUrl: "/experimentsPlace",
          },{
             powerName: "被测装备",
             powerUrl: "/experimentsTestEquipment",
          }]
        },{
          powerName: "统计",
          // powerUrl: "/statisticsOverview",
          children: [{
             powerName: "总览",
             powerUrl: "/statisticsOverview",
          },{
             powerName: "人员",
             powerUrl: "/statisticsPersonnel",
          },{
             powerName: "场地",
             powerUrl: "/statisticsPlace",
          },{
             powerName: "试验装备",
             powerUrl: "/statisticsEquipment",
          },{
             powerName: "被测装备",
             powerUrl: "/statisticsTestEquipment",
          },{
             powerName: "任务",
             powerUrl: "/statisticsTask",
          },{
             powerName: "科目",
             powerUrl: "/statisticsSubject",
          }]
        },{
          powerName: "系统设置",
          // powerUrl: "/userManage",
          children: [{
             powerName: "用户管理",
             powerUrl: "/userManage",
          },{
             powerName: "用户组管理",
             powerUrl: "/userGroupManage",
          },{
             powerName: "部门管理",
             powerUrl: "/departmentManage",
          }]
        }, ];
      // this.tomorrowDate = (new Date(Date.now() + 24 * 60 * 60 * 1000)).Format("yyyy-MM-dd");
    },
    mounted() {
      this.userName = localStorage.getItem('userName');
      this.userId = localStorage.getItem('userId');
      // this.menuList = sessionStorage.getItem("menuList");


     this.setMenu(this.$route.path);



      
      // this.asyncGetAirportList()
    },
    methods: {
      
      //用户信息--弹框交互
      onClickCancelSave() {
        this.isDialogVisible = false;
      },
      //保存用户信息
      onClickAddSaveData() {
        this.isDialogVisible = false;
      },
      //取消--用户修改密码--弹框交互
      onClickCancelPwd() {
        this.isDialogPwd = false;
        this.oldPwd = '';
        this.newPwd = '';
        this.newPwdBak = '';
      },
      //取消--我的档案弹框
      onClickCancelInfo() {
        this.isDialogBaseInfo = false;
      },
      //修改--我的档案
      onClickEditInfo() {
        this.isDialogBaseInfo = false;
        this.isDialogVisible = true;
      },
      //获取我的档案
      onClickMyInfo() { 
        this.isDialogBaseInfo = true;
         this.$axios.get("/user/getUserInfoVo?id="+this.userId).then(res => {
          if (res.data.code === 200) {
            let data = res.data.data;
            Object.keys(data).forEach((item) => {
              this[item] = data[item];
            });
          } else {
            this.$message.error(res.data.msg)
          }
        })
      },
      //保存--用户修改密码
      onClickAddSavePwd() {
        if (this.oldPwd == ''){
            this.$message.error('请输入原密码');
        } else if (this.oldPwd.length<6){
            this.$message.error('密码长度为6~20位');
        } else if (this.newPwd == ''){
            this.$message.error('请输入新密码');
        } else if (this.newPwd.length<6){
            this.$message.error('新密码长度为6~20位');
        } else if (this.newPwdBak == ''){
            this.$message.error('请输入重复新密码');
        } else if (this.newPwdBak != this.newPwd){
            this.$message.error('两次新密码不一致');
        } else {
          let _obj = {
              id: this.userId,
              originPwd:md5(this.oldPwd),
              newPwd: md5(this.newPwdBak),
          };
            this.$axios.post("/user/updatePwdById", { 
            _obj
          }).then((res) => {
            if (res.data.code === 200) {
              this.onClickCancelPwd();
            } else {
              this.$message.error(res.data.msg);
            }
          })
        }
      },



    //刷新页面后对应样式高亮
    setMenu(parentUrl) {
        console.log('哈哈哈哈');
        console.log(parentUrl);
        parentUrl = '/' + parentUrl.split('/')[1];
        this.menuList && this.menuList.map((item,index) => {
          if (parentUrl === item.powerUrl) {
            this.curPathIndex = index;
            // this.$router.push(item.powerUrl);
          } else if (parentUrl !== item.powerUrl && item.children.length > 0) {
            item.children.forEach((val,idx) => {
              if (parentUrl === val.powerUrl) {
                this.curPathIndex = index;
                this.curPath = idx.toString();
                this.menuItemList = item.children;
                // this.$router.push(val.powerUrl);
                console.log(item.children);
               
              }
            })
          } 
        });
        console.log('this.menuItemList');
        console.log(this.menuItemList);
      },
      //点击--父级菜单
      onClickMenuItem(item,idx) {
        this.curPathIndex = idx;
        if(item.children.length>0) {
          this.curPath = '0';
          this.menuItemList = item.children;
          this.$router.push(this.menuItemList[this.curPath].powerUrl);
          console.log(this.menuItemList[this.curPath].powerUrl)
          console.log('1')

        } else {
          /* this.curPath = '';*/
          this.menuItemList = []; 
          this.$router.push(item.powerUrl);
          console.log('2')

        }
      },
      //点击--当前子级菜单
      onClickCurrentPath() {
          this.$router.push(this.menuItemList[this.curPath].powerUrl);
      },
      //点击--修改密码
      onClickPwd() {
        this.isDialogPwd = true;
      },
      //点击--退出
      clickLogoutBtn() {
        this.$axios.get("/user/logout").then(res => {
          if (res.data.code === 200) {
            localStorage.clear();
            this.$router.push({
              path: "/login"
            })
          } else {
            this.$message.error(res.data.msg)
          }
        })
      },
      
    },
    watch: {
      $route() {
        // this.setMenu(this.$route.path);
      }
    }
  }
</script>

<style scoped lang="scss">
  .header-container {
    min-width: 970px;
    height: 50px;
    line-height: 50px;
    padding-left:30px;
    font-size: 18px;
    background-color: rgb(73,114,232);
    color: #ffffff;
  }
</style>
